<template>
	<view style="height: 100rpx;" class="fixed-bottom flex align-center border-top bg-white">
		<view  style="display: flex;">
			<view class="iconfont icon-smile flex align-center justify-center font-lg animated" hover-class="jello text-main" style="width: 100rpx;" @click="selectEmoji"></view>
			<input type="text" v-model="content" class="flex-1 rounded bg-light ml-2" style="padding: 5rpx;width: 460rpx;" :focus="focus" placeholder="文明发言" @confirm="submit" @blur="$emit('blur')"/>
			
			<view class="iconfont icon-huati flex align-center justify-center font-lg animated" hover-class="jello text-main" style="width: 50rpx;" @click="huati" v-if="nowTable=='yisheng'"></view>
			
			<view class="iconfont icon-tupian flex align-center justify-center font-lg animated" hover-class="jello text-main" style="width: 50rpx;" @click="Image"></view>
			<view class="iconfont icon-fabu flex align-center justify-center font-lg animated" hover-class="jello text-main" style="width: 100rpx;" @click="submit"></view>	
		</view>	      
	    <apply-bar :show="specSelection" ref="paygoods"  @applayCancel="applayCancel" @chooseCancel="chooseCancel"></apply-bar>	
	</view>

		
		
</template>

<script>
	import apply from "@/components/apply/index.vue";
	export default {
		components: {
			"apply-bar": apply,
		 },
		props: {
			focus: {
				type: Boolean,
				default: false
			},
		},
		data() {
			return {
				content: "",
				specSelection: false, // 控制弹窗显示
				ToUser:{},
				nowTable:'',
				
				
			}
		},
		
		methods: {
			submit() {
				// 是否为空
				if (this.content === '') {
					return uni.showToast({
						title: '消息不能为空',
						icon: 'none'
					});
				}
				this.$emit('submit',this.content,'text')
				// 清空输入框
				this.content = ''
			},
			
			huati(){
				this.specSelection=true
				this.$refs.paygoods.showGoods(this.ToUser)
				
			},
			
			showToUser(event){
				this.ToUser=event
				this.nowTable=uni.getStorageSync("nowTable")
				console.log('888',this.nowTable)
			},
			applayCancel(evnet){
				this.specSelection=false
				this.$emit('submit','医生推送一个处方，请去处方列表查看！','text')
				console.log('event-----ok---',evnet)
			},
			chooseCancel(){
			  this.specSelection=false	
			},

			selectEmoji() {
      uni.showActionSheet({
        itemList: ['😀', '😂', '😍', '👍', '👎'],
        success: res => {
          const selected = res.tapIndex;
          switch (selected) {
            case 0:
              this.content += '\uD83D\uDE00';
              break;
            case 1:
              this.content += '\uD83D\uDE02';
              break;
            case 2:
              this.content += '\uD83D\uDE0D';
              break;
            case 3:
              this.content += '\uD83D\uDC4D';
              break;
            case 4:
              this.content += '\uD83D\uDC4E';
              break;
            default:
              break;
          }
        }
      })
    },
			
			Image(){
				uni.chooseImage({
					count: 1, //最多可以选择的图片张数，默认9
					sizeType: ['compressed'],     //original 原图，compressed 压缩图，默认二者都有
					sourceType: ['album'], 
					success: (res) => {           //成功返回的函数
					console.log('图片路径为：', res.tempFilePaths[0]) //选着的图片
						var imageSrc = res.tempFilePaths[0] //将图片的地址赋值给imageSrc
						this.$H.upload('Api/upload',{
							filePath: imageSrc,
							name: 'file',
							token:true
						}).then(result=>{
							// console.log('result','https://inquiry.zhuangdongxiang.cn/upload/'+result.file)
							this.$emit('submit','https://inquiry.zhuangdongxiang.cn/upload/'+result.file,'image')
							
						})
												
					},
					fail: (err) => {              //图片接口调用失败的回调函数	
					console.log('chooseImage fail', err)
					}
				}) 
			}
		},
	}
</script>

<style>
</style>
